package com.pxxy.yuyi.controller;

import com.github.pagehelper.PageInfo;
import com.pxxy.yuyi.entity.Admin;
import com.pxxy.yuyi.entity.Employment;
import com.pxxy.yuyi.service.EmploymentService;
import com.pxxy.yuyi.utils.ConstUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
;import javax.servlet.http.HttpServletRequest;

/**
 * Created by IntelliJ IDEA
 *
 * @Author : XuWen
 * @create 2021/6/20 22:31
 */
@Controller
@RequestMapping("/employ")
public class EmploymentController {
    @Autowired
    private EmploymentService employmentService;
    //前端提交招聘信息
    @RequestMapping("/addemploy")
    public String addemploy(Employment employment, HttpServletRequest request){
        Integer res=employmentService.insertemployment(employment);
        if(res==null){
            request.setAttribute("mes","提交失败");
            return "ContactFrom";
        }
        request.setAttribute("mes","提交成功！");
        return "ContactFrom";
    }
    //后台展示招聘信息
    @RequestMapping("/showEmploy")
    public String showEmploy(HttpServletRequest request,Integer pageNum){
        if (pageNum==null){
            pageNum=1;
        }
        Admin admin = (Admin) request.getSession().getAttribute(ConstUtils.LOGIN_USER);
        if (admin==null) {//为空则先进行登录
            request.setAttribute("msg", "请先登录");
            return "admin/adminLogin";
        }
        PageInfo<Employment> info = employmentService.showEmploy(pageNum);
        request.setAttribute("pi",info);
        return "admin/employment";
    }
    //后台删除招聘信息
    @RequestMapping("/delete")
    public String delete(Integer eid){
        employmentService.deleteEmployment(eid);
        return "forward:/employ/showEmploy";
    }

}
